#include "Queue.h"

void Queue_Init(Queue *q)
{
	q->head = q->tail = NULL;
	q->size = 0;
}

void Queue_Add(Queue* q, int first, int second)
{
	QueueNode *node = (QueueNode*)malloc(sizeof(QueueNode));
	node->first = first;
	node->second = second;
	if (q->size == 0)
	{
		node->prev = node->next = 0;
		q->head = q->tail = node;
	}
	else
	{
		node->prev = q->tail;
		node->next = 0;
		q->tail->next = node;
		q->tail = node;
	}
	q->size++;
}

void Queue_Remove(Queue* q, int *first, int *second)
{
	QueueNode *node;
	
	if(q->size > 0)
	{
		node = q->head;
		*first = node->first;
		*second = node->second;
		q->head = node->next;
		if (q->size == 1)
		{
			q->tail = 0;
		}
		q->size--;
		free(node);
	}	
}